const mysql = require('mysql')
const { mysql_conf } = require('../conf/db')

const connection = mysql.createConnection(mysql_conf)

// 创建连接对象
connection.connect()


// 统一执行sql的函数
function execquery(sql) {
  const promise = new Promise((resolve, reject) => {
    connection.query(sql, (err, result) => {
      if (err) {
        reject(err)
        return
      }
      resolve(result)
    })
  })
  return promise
}


module.exports = {
  execquery
}